﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Xml;

namespace Microsoft.SharePoint
{
  public class SPSite : IDisposable
  {
    public XmlNode node = null;
    public string Url { get { return ((XmlElement)node).GetAttribute("@Url"); } }
    public bool AllowUnsafeUpdates { get; set; }

    public SPSite(XmlNode node)
    {
      this.node = node;
    }

    public SPSite(string requestUrl)
    {
      node = SPContext.content.SelectSingleNode("//Site[@Url=" + Url + "]");
    }

    public SPSite(Guid guid)
    {
      XmlNode node = SPContext.content.SelectSingleNode("//Site[@Guid=" + guid.ToString() + "]");
    }

    public SPWeb OpenWeb()
    {
      return new SPWeb(node.SelectSingleNode("//Web"));
    }

    public SPWeb OpenWeb(string strUrl)
    {
      return new SPWeb(node.SelectSingleNode("//Web[@Url=" + strUrl + "]"));
    }

    public SPWeb OpenWeb(Guid guid)
    {
      return new SPWeb(node.SelectSingleNode("//Web[@Guid=" + guid + "]"));
    }

    public void Dispose()
    {
      if (this == SPContext.Current.Site)
        throw new Exception("Shouldn't dispose this object - it is managed by the SharePoint framework");
    }
  }
}
